package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SysCompeScoringDetails;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.SysCompeScoringDetailsService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 柳
 * @Date 2021/3/30
 * @Description TODO
 */
@RestController
@RequestMapping("/system/scoringdetails")
public class SysCompeScoringDetailsController {
    @Autowired
    private SysCompeScoringDetailsService sysCompeScoringDetailsService;

    @Autowired
    private ISysUserService sysUserService;

    @GetMapping("/querySysCompeScoringDetails")
    @ApiOperation("根据赛事查询评分详情信息")
    public AjaxResult querySysCompeScoringDetails(SysCompeScoringDetails sysCompeScoringDetails) {
        if(sysCompeScoringDetails==null||StringUtils.isBlank(sysCompeScoringDetails.getWork_id())||StringUtils.isBlank(sysCompeScoringDetails.getCompe_id().toString())||StringUtils.isBlank(sysCompeScoringDetails.getUser_id())){
            return AjaxResult.error();
        }
        try {
            List<SysCompeScoringDetails> sysCompeScoringDetails1 = sysCompeScoringDetailsService.querySysCompeScoringDetails(sysCompeScoringDetails);
            return AjaxResult.success(sysCompeScoringDetails1);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }


    @PostMapping("/saveSysCompeScoringDetails")
    @ApiOperation("添加评分详情信息")
    public AjaxResult saveSysCompeScoringDetails(@RequestBody List<SysCompeScoringDetails> sysCompeScoringDetailsList) {
        if(sysCompeScoringDetailsList.size()==0){
            return AjaxResult.error();
        }
        for (SysCompeScoringDetails sysCompeScoringDetails : sysCompeScoringDetailsList) {
            //添加评分详情信息
            sysCompeScoringDetailsService.saveSysCompeScoringDetails(sysCompeScoringDetails);
        }
        return AjaxResult.success();
    }
}
